package com.auction.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 定时任务配置类
 */
@Configuration
@EnableScheduling
public class TaskConfig {

    /**
     * 配置线程池任务调度器
     */
    @Bean
    public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(10); // 设置线程池大小
        scheduler.setThreadNamePrefix("auction-task-"); // 线程名前缀
        scheduler.setWaitForTasksToCompleteOnShutdown(true); // 等待所有任务完成再关闭
        scheduler.setAwaitTerminationSeconds(60); // 等待时间
        return scheduler;
    }
}